#define _GNU_SOURCE
#include <curl/curl.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <regex.h>

#ifndef DATA_TYPE_H
#define DATA_TYPE_H

#define DATA_BUFFER_SIZE 16384
#define DATA_BUFFER_SIZE_1K 1024


//********************************************************************
//	data_buffer
//
//********************************************************************
struct data_buffer {
	char *contentPtr;// data startPtr,end with '\0'
	unsigned long dataSize; //content size
	unsigned long buffSize; // contentPtr total size
};

void * data_buffer_init_1k(struct data_buffer *db);
void * data_buffer_init_16k(struct data_buffer *db);
bool data_buffer_reset_1k(struct data_buffer *db);
bool data_buffer_reset_16k(struct data_buffer *db);
bool data_buffer_equal(struct data_buffer*,struct data_buffer*);
void data_buffer_duplicate(struct data_buffer*,struct data_buffer*);
void data_buffer_destroy(struct data_buffer *db);
void * data_buffer_resize(struct data_buffer *db);
void * add_data(struct data_buffer *db,const char *dataPtr,long dataSize);



//********************************************************************
//	int_queue_node struct
//
//********************************************************************
struct int_queue_node {
	int node_value;
	struct int_queue_node* next;
};

struct int_queue_node * int_queue_init(void);
void destroy_int_queue(struct int_queue_node*);
void* in_queue(struct int_queue_node*,int node_value);
bool out_queue(struct int_queue_node*,int* ret_node_value);
bool queue_empty(struct int_queue_node*);
bool value_in_queue(struct int_queue_node*,int);


//*********************************************************************
//	order info struct
//
//********************************************************************
struct order_info{
	long id;
	long tb_order_id;
	char operate[2];		// '0'->停  '1'->开
	char start_date[11];		// '2024-04-01'
	char end_date[11];
	char start_time[9];		// '21:00:00'
	char end_time[9];
	char days[8];			// '1234567'
	char order_type_name[17];	//'对外广播' 一个汉字占用按四个 and '\0'
	char order_type[2];
	char channel[4];
	int antenna_prog_id;
	int freq;
	char azimuth[10];		//641 206天线角度是353.7
	char actual_power[7];
	char op_status[3];
	char trans_name[4];
	char ant_used_code[4];
	char reason[51];
	char station_name[11];
	char prog_desc[26];
	char program_name[11];
	char ant_prog_desc[17];
	char feedback_status[3];
	char actual_start[30];
	char mod[2];
};


//*********************************************************************************************
//	order_info queue structure
//
//*********************************************************************************************
struct order_info_node {
	struct order_info order;
	struct order_info_node *next;
};

struct order_info_node* orders_init(void);
void orders_destroy(struct order_info_node *);
bool orders_empty(struct order_info_node*);
bool add_orders(struct order_info_node*,struct order_info*);
bool out_orders(struct order_info_node*,struct order_info*);
void duplicate_orders(struct order_info_node*,struct \
		order_info_node*);
//*********************************************************************************************
//	order_page structure
//
//*********************************************************************************************
struct order_page{
	long tb_order_id;
	int  order_year;
	char station_id[5];
	char order_code[30];
	char send_date[20];
	char recv_date[20];
	//...
	struct order_info_node *orders;
};

//struct order_page* duplicate_order_page(struct order_page*);
bool order_page_init(struct order_page *);
void order_page_destroy(struct order_page*);
bool duplicate_order_page(struct order_page*,struct order_page*);



//*********************************************************************
//	http_thread_argument struct 
//
//*********************************************************************
struct http_thread_arg{
	CURL *curl;
	struct order_page page_info;
	//struct int_queue_node* id_queue;
	//char *http_content;
	//char *http_header;
	//int *ret;
};

//*********************************************************************
//	net_check_argument struct 
//
//*********************************************************************
struct net_thread_arg{
	CURL* curl;
	char cookies[1024];
};

//*********************************************************************************************
//	order_page_queue structure
//
//*********************************************************************************************
struct order_page_node{
	struct order_page order_page;
	struct order_page_node *next;
};


struct order_page_node* order_pages_init(void);
void order_pages_destroy(struct order_page_node*);
bool order_pages_empty(struct order_page_node*);
bool add_order_pages(struct order_page_node *,struct order_page*);
bool out_order_pages(struct order_page_node*,struct order_page*);


//********************************************************************************************
//	websocket data buffer structure
//
//*******************************************************************************************
	/*struct data_buffer {
		char *contentPtr;// data startPtr,end with '\0'
		unsigned long dataSize; //content size
		unsigned long buffSize; // contentPtr total size
	};*/
struct ws_data_node{
	struct data_buffer ws_data;
	struct ws_data_node *next;
};

struct ws_data_node* ws_data_queue_init(void);
void ws_data_queue_destroy(struct ws_data_node*);
bool ws_data_empty(struct ws_data_node*);
bool add_ws_data(struct ws_data_node*,struct data_buffer*);
bool out_ws_data(struct ws_data_node*,struct data_buffer*);
void print_all_ws_data(struct ws_data_node*);


















#endif
